<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>eventloop事件机制1230429中</title>
</head>
<body>
    <script>
        // setTimeout(function () { console.log(1) }, 0);
        // new Promise(function (resolve, reject) {
        //     console.log(2);
        //     resolve();
        // }).then(function () {
        //     console.log(3)
        // }).then(function () { console.log(4) });
        // process.nextTick(function () { console.log(5) });
        // console.log(6);
        //event loop事件机制
        //  setTimeout(function(){
        //     console.log(2)
        //  },0)
        //  console.log(1)
         // 1 2
         setTimeout(function(){
            console.log(3)
         },0)
         Promise.resolve().then(function(){
            console.log(2)
         })
         console.log(1)
         //工作任务 macro-task micro-task
         // macro-task a1 a2 a3
         //micro-task b1 b2 b3
         // a1 b1 b2 b3 a2 b1 b2 ....
        //script(主程序代码)—>process.nextTick—>Promises...
        //——>setTimeout——>setInterval——>setImmediate——> I/O——>UI rendering
        //1 2 3
    </script>
</body>
</html>